package com.base;

import java.util.Iterator;

/**
 * @author: sun.hongliang
 * @create: 2019/04/08 12:27
 */
public class MyIterator implements Iterable<Character> {
    private int length = 0;
    private String ineers = null;

    public MyIterator(String s) {
        this.ineers = s;
        this.length = s.length();

    }

    @Override
    public Iterator<Character> iterator() {
        class iter implements Iterator<Character> {
            private int cur = 0;

            @Override
            public boolean hasNext() {
                return cur != length;
            }

            @Override
            public Character next() {
                Character c = ineers.charAt(cur);
                cur++;
                return c;
            }

            public void remove() {
            }
        }
        return new iter();
    }

    public static void main(String[] args) {
        MyIterator s = new MyIterator("1234567");
        for (char c : s) {
            System.out.println(c);
        }
    }

}
